package cc.miwuya.property.service.impl;

import cc.miwuya.property.domain.House;
import cc.miwuya.property.domain.Meter;
import cc.miwuya.property.mapper.MeterMapper;
import cc.miwuya.property.service.HouseService;
import cc.miwuya.property.service.MeterItemService;
import cc.miwuya.property.service.MeterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 杩烽浘妫灄
 * @description 针对表【meter(计量表)】的数据库操作Service实现
 * @createDate 2024-02-22 19:49:08
 */
@Service
public class MeterServiceImpl extends ServiceImpl<MeterMapper, Meter>
        implements MeterService {
    @Resource
    MeterItemService meterItemService;
    @Override
    public Object getResidentialList(Page page, Long residentialId,Integer meterType) {
        //根据小区ID获取当前小区的所有的房屋ID
        Page<Meter> meterPage;
        meterPage = page(page,new QueryWrapper<Meter>().eq("residential_id",residentialId).eq("type",meterType));
        for (Meter record : meterPage.getRecords()) {
            record.setMeterItem(meterItemService.getByMeterId(record.getId()));
        }
        return meterPage;
    }

    @Override
    public Object getOwnerMeterList(Long ownerId, Integer meterType) {
        List<Meter> list;
        if (meterType == -1){
            list = list(new QueryWrapper<Meter>().eq("home_id", ownerId));
        }else {
            list = list(new QueryWrapper<Meter>().eq("home_id", ownerId).eq("type",meterType));
        }

        for (Meter meter : list) {
            meter.setMeterItem(meterItemService.getByMeterId(meter.getId()));
        }
        return list;
    }

}




